/**
 * The file for the Planet class.
 */

package edu.gatech.information;

import java.awt.Color;
import java.util.Random;
/**
 * This is the Planet class.
 * @author Hippie Mind Control
 * @version 1.0
 */

public class Planet {
	
	/** The economy */
	private Economy economy;
	
	/** The government */
	private Government government;
	
	/** The color */
	private Color color;
	
	/** The radius and x-y coordinates */
	/**Climate type is a random int from 0 to 10, 0 is freezing and 10 is too hot*/
	private int radius, xPos, yPos;
	
	/** The mods for economy, government, and resource */
	private int[]  econMod, governMod, specialResourceMod;
	
	/** The name */
	private String name;
	
	/** The special resource */
	private SpecialResource specialResource;
	
	/** The marketplace */
	private MarketPlace marketplace;

	/**
	 * This initializes all the variables associated with a Planet.
	 */
	public Planet() {
		economy = randomEconomy();
		government = randomGovernment();
		specialResource = randomSpecialResource();
		color = new Color(new Random().nextInt(256),
				new Random().nextInt(256),
				new Random().nextInt(256));
		radius = new Random().nextInt(10) + 5;
		xPos = new Random().nextInt(700) + 50;
		yPos = new Random().nextInt(400) + 50;
		name = "";
		econMod = generateEconMod(economy);
		governMod = generateGovernMod(government);
		specialResourceMod = generateSpecialResourceMod(specialResource);
		marketplace = new MarketPlace(econMod, governMod, specialResourceMod);
	}

	/**
	 * Enum list of Resources that are available for purchase.
	 *
	 */
	public enum Resource {
		WATER,
		FURS,
		FOOD,
		ORE,
		GAMES,
		FIREARMS,
		MEDICINE,
		MACHINE,
		NARCOTICS,
		ROBOTS,
	}

	/**
	 * Creates and enum list of the Economy types.
	 *
	 */
	public enum Economy {
		PRE_AGRICULTURE,
		AGRICULTURE,
		MEDIEVAL,
		RENAISSANCE,
		EARLY_INDUSTRIAL,
		INDUSTRIAL,
		POST_INDUSTRIAL,
		HI_TECH,
	}
	
	/**
	 * Randomly generates what Economy the Planet will have.
	 * @return Economy
	 */
	private Economy randomEconomy() {
	    int pick = new Random().nextInt(Economy.values().length);
	    return Economy.values()[pick];
	}
	
	/**
	 * Generates a price modifier based on the economy type
	 * @param econ
	 * @return the price modifier int value
	 */
	private int[] generateEconMod(Economy econ) {
		switch(econ) {
			case PRE_AGRICULTURE:
				return new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
			case AGRICULTURE:
				return new int[] {1, 1, 3, 2, 1, 1, 1, 1, 1, 1};
			case MEDIEVAL:
				return new int[] {1, 1, 3, 3, 1, 3, 1, 1, 1, 1};
			case RENAISSANCE:
				return new int[] {1, 2, 1, 1, 5, 1, 1, 1, 1, 1};
			case EARLY_INDUSTRIAL:
				return new int[] {10, 2, 1, 4, 1, 1, 3, 8, 1, 1};
			case INDUSTRIAL:
				return new int[] {1, 2, 1, 6, 2, 5, 1, 20, 1, 1};
			case POST_INDUSTRIAL:
				return new int[] {9, 2, 5, 2, 5, 4, 10, 7, 3, 8};
			case HI_TECH:
				return new int[] {1, 2, 1, 4, 5, 2, 1, 9, 10, 10};
		}
		return new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
	}
	
	/**
	 * Creates an enum list of the Government options.
	 *
	 */
	public enum Government {
		ANARCHY,
		CAPITALIST_STATE,
		COMMUNIST_STATE,
		CONFEDERACY,
		CORPORATE_STATE,
		CYBERNETIC_STATE,
		DEMOCRACY,
		DICTATORSHIP,
		FASCIST_STATE,
		MILITARY_STATE,
		MONARCHY,
		PACIFIST_STATE,
		SOCIALIST_STATE,
		STATE_SATORI,
		TECHNOCRACY,
		THEOCRACY,
	}
	
	/**
	 * Generates the price modifier based on the type of government
	 * @param govern
	 * @return the int value of the price modifier
	 */
	private int[] generateGovernMod(Government govern) {
		switch(govern) {
			case ANARCHY:
				return new int[] {1, 3, 2, 1, 1, 0, 1, 4, 0, 1};
			case CAPITALIST_STATE:
				return new int[] {4, 1, 1, 2, 1, 0, 1, 1, 0, 1};
			case COMMUNIST_STATE:
				return new int[] {1, 2, 2, 3, 1, 0, 1, 3, 0, 1};
			case CONFEDERACY:
				return new int[] {7, 5, 6, 2, 0, 2, 1, 4, 1, 1};
			case CORPORATE_STATE:
				return new int[] {1, 1, 1, 1, 4, 5, 2, 7, 2, 3};
			case CYBERNETIC_STATE:
				return new int[] {1, 1, 1, 4, 7, 1, 6, 8, 1, 5};
			case DEMOCRACY:
				return new int[] {5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
			case DICTATORSHIP:
				return new int[] {4, 1, 3, 2, 0, 0, 1, 3, 0, 1};
			case FASCIST_STATE:
				return new int[] {2, 1, 8, 2, 1, 0, 5, 1, 0, 10};
			case MILITARY_STATE:
				return new int[] {4, 1, 0, 2, 1, 15, 10, 5, 0, 1};
			case MONARCHY:
				return new int[] {7, 1, 1, 2, 1, 1, 4, 5, 5, 1};
			case PACIFIST_STATE:
				return new int[] {1, 2, 2, 3, 15, 0, 1, 3, 10, 8};
			case SOCIALIST_STATE:
				return new int[] {1, 2, 2, 3, 1, 0, 1, 4, 10, 3};
			case STATE_SATORI:
				return new int[] {2, 2, 2, 0, 2, 2, 2, 2, 2, 13};
			case TECHNOCRACY:
				return new int[] {1, 2, 2, 13, 1, 0, 11, 14, 10, 15};
			case THEOCRACY:
				return new int[] {3, 2, 5, 2, 0, 1, 4, 2, 5, 1};
		}
		return new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
	}
	
	/**
	 * Randomly generates what type of Government the Planet will have.
	 * @return Government
	 */
	private Government randomGovernment() {
	    int pick = new Random().nextInt(Government.values().length);
	    return Government.values()[pick];
	}
	
	/**
	 * Creates an enum list of the possible Special Resources the Planet could have.
	 *
	 */
	public enum SpecialResource {
		NO_SPECIAL_RESOURCE,
		MINERAL_RICH,
		MINERAL_POOR,
		DESERT,
		LOTS_OF_WATER,
		RICH_SOIL,
		POOR_SOIL,
		RICH_FAUNA,
		LIFELESS,
		WEIRD_MUSHROOMS,
		LOTS_OF_HERBS,
		ARTISTIC,
		WARLIKE,
	}
	
	/**
	 * Create the special resource modifier int value
	 * @param special
	 * @return int value of the special resource modifier
	 */
	private int[] generateSpecialResourceMod(SpecialResource special) {
		switch(special) {
			case NO_SPECIAL_RESOURCE:
				return new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
			case MINERAL_RICH:
				return new int[] {3, 1, 2, 4, 1, 1, 1, 1, 1, 1};
			case MINERAL_POOR:
				return new int[] {0, 1, 1, 0, 1, 1, 1, 1, 1, 1};
			case DESERT:
				return new int[] {0, 1, 1, 1, 1, 1, 1, 1, 1, 1};
			case LOTS_OF_WATER:
				return new int[] {5, 1, 1, 1, 1, 1, 1, 1, 1, 1};
			case RICH_SOIL:
				return new int[] {1, 1, 5, 1, 1, 1, 1, 1, 1, 1};
			case POOR_SOIL:
				return new int[] {1, 1, 0, 1, 1, 1, 1, 1, 1, 1};
			case RICH_FAUNA:
				return new int[] {1, 5, 1, 1, 1, 1, 1, 1, 1, 1};
			case LIFELESS:
				return new int[] {1, 0, 0, 1, 1, 1, 1, 1, 1, 1};
			case WEIRD_MUSHROOMS:
				return new int[] {1, 1, 1, 1, 1, 1, 1, 1, 5, 1};
			case LOTS_OF_HERBS:
				return new int[] {1, 1, 1, 1, 1, 1, 3, 1, 1, 1};
			case ARTISTIC:
				return new int[] {1, 1, 1, 1, 1, 1, 1, 1, 3, 1};
			case WARLIKE:
				return new int[] {1, 1, 1, 1, 1, 3, 1, 1, 1, 1};
		}
		return new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
	}
	
	/**
	 * Randomly generates the Special Resource that the Planet will have.
	 * @return A random special resource.
	 */
	private SpecialResource randomSpecialResource() {
		int pick = new Random().nextInt(SpecialResource.values().length);
	    return SpecialResource.values()[pick];
	}
	
	/**
	 * Gets the government type
	 * @return government
	 */
	public Government getGovernment() {
		return government;
	}
	
	/**
	 * Sets the government type
	 * @param government
	 */
	public void setGovernment(Government government) {
		this.government = government;
	}
	
	/**
	 * Gets the economy type
	 * @return economy
	 */
	public Economy getEconomy() {
		return economy;
	}
	
	/**
	 * Sets the economy type
	 * @param economy
	 */
	public void setEconomy(Economy economy) {
		this.economy = economy;
	}
	
	/**
	 * Gets the name of the Planet
	 * @return name
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Sets the name of the Planet
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * Gets the color of the Planet
	 * @return color
	 */
	public Color getColor() {
		return color;
	}
	
	/**
	 * Sets the color of the Planet
	 * @param color
	 */
	public void setColor(Color color) {
		this.color=color;
	}
	
	/**
	 * Gets the radius of the Planet
	 * @return radius
	 */
	public int getRadius() {
		return radius;
	}
	
	/**
	 * Sets the radius of the Planet
	 * @param radius
	 */
	public void setRadius(int radius) {
		this.radius = radius;
	}
	
	/**
	 * Gets the xPos of the Planet on the screen
	 * @return xPos
	 */
	public int getXPos() {
		return xPos;
	}
	
	/**
	 * Sets the xPos of the Planet on the screen
	 * @param xPos
	 */
	public void setXPos(int xPos) {
		this.xPos = xPos;
	}
	
	/**
	 * Gets the yPos of the Planet on the screen
	 * @return yPos
	 */
	public int getYPos() {
		return yPos;
	}
	
	/**
	 * Sets the yPos of the Planet on the screen
	 * @param yPos
	 */
	public void setYPos(int yPos) {
		this.yPos = yPos;
	}
	
	/**
	 * To String method for the Planet class
	 * @return A string representation of Planet.
	 */
	public String toString() {
		String str = "";
		str += name + " ";
		str += "(" + xPos + ", " + yPos + ")\n";
		return str;
	}
	
	/**
	 * Gets the special resource of the Planet
	 * @return specialResourse
	 */
	public SpecialResource getSpecialResource() {
		return specialResource;
	}
	
	/**
	 * Sets the special resource of the Planet
	 * @param specialResource The new special resource.
	 */
	public void setSpecialResource(SpecialResource specialResource) {
		this.specialResource = specialResource;
	}
	
	/**
	 * Gets the marketplace.
	 *
	 * @return the marketplace
	 */
	public MarketPlace getMarketplace() {
		return marketplace;
	}
	
	/**
	 * Checks to see if the input to the method is on the drawn planet
	 * @param x1
	 * @param y1
	 * @return true
	 */
	public boolean contains(int x1, int y1) {
		if (x1 >= (getXPos()-getRadius()) && x1<=(getXPos()+2*getRadius()) && y1>=(getYPos()-getRadius()) && y1<=(getYPos()+2*getRadius())) {
            return true;
	    }
	    else {
	    	return false;
	    }
	}
	
	/**
	 * This was used to save what economy, government and special resouce each planet has
	 * @return saveString
	 */
	public String saveString(){
		String saveString = "";
		saveString += economy.ordinal() + ","
			+ government.ordinal() + ","
			+ specialResource.ordinal() + ","
			+ radius + ","
			+ xPos + ","
			+ yPos + ",";
		return saveString;
	}
}